import requests
import json

import os
from dotenv import load_dotenv

load_dotenv(verbose=True)
AT = os.getenv("WENXIN_ACCESSTOKEN")

def call_llm(user_prompt, system_prompt=''):
    url = f'https://aip.baidubce.com/rpc/2.0/ai_custom/v1/wenxinworkshop/chat/eb-instant?access_token={AT}'
    # print(url)

    payload = json.dumps({
        "messages": [
            {
                "role": "user",
                "content": user_prompt
            }
        ],
        "system": system_prompt,
        "temperature": 0.1,
    })

    # print(payload)
    headers = {
        'Content-Type': 'application/json'
    }
    response = requests.request("POST", url, headers=headers, data=payload)
    # print(response.text)
    return response.json()['result']

